﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMain;

namespace Items
{
    public abstract class Item : WorldElement
    {
        private String description;
        private double value;
        private double size;
        private double weight;
        private int stackCur;
        private int stackMax;

        public String Description {
            get { return description; }
        }
        public double Value {
            get { return GetValue(); } 
        }
        public double Size {
            get { return size; }
        }
        public double Weight {
            get { return GetWeight(); }
        }
        public int Stacked {
            get { return stackCur; }
        }
        public int StackSize { 
            get { return stackMax; } 
        }

        public Item()
        {
            SetName("Item");
            SetType("Item");
        }

        public Item(String inName, String inDescription, double inValue, double inSize, double inWeight, int inStackMax) : base(inName)
        {
            SetType("Item");
            description = inDescription;
            value = inValue;
            size = inSize;
            weight = inWeight;
            stackMax = inStackMax;
            stackCur = 1;
        }

        public Item(String inName, String inDescription, double inValue, double inSize, double inWeight, int inStackMax, int inStackCur) : base(inName)
        {
            SetType("Item");
            description = inDescription;
            value = inValue;
            size = inSize;
            weight = inWeight;
            stackMax = inStackMax;
            stackCur = inStackCur;
        }

        protected double GetValue()
        {
            /*Do calculations if there are discounts or raised prices*/
            return value;
        }

        protected double GetWeight()
        {
            return (double) weight * stackCur;
        }

        /// <summary>
        /// Determines if an item can be added to the current stack
        /// </summary>
        /// <returns>True if the item can stacked, false otherwise</returns>
        public bool CanAdd(int amount)
        {
            if (stackCur + amount <= stackMax)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Adds an input amount of Items to the stack if possible
        /// </summary>
        /// <param name="amount">How many to attempt to add to the stack</param>
        /// <returns>The amount that couldn't be added to the stack</returns>
        public int AddItems(int amount)
        {
            if ((stackCur + amount) > stackMax)
            {
                stackCur = stackMax;
                return (stackCur + amount) - stackMax;
            }

            stackCur += amount;
            return 0;
        }

        /// <summary>
        /// Takes an item from the stack
        /// </summary>
        /// <returns>True if the stack is empty, false otherwise</returns>
        public bool Use()
        {
            stackCur--;
            return stackCur == 0;
        }
    }
}
